﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AvaliacaoOnline.Model;

namespace Avaliacao.Controllers
{
    public class GestaoController : BaseController
    {
        //
        // GET: /Gestao/

        public ActionResult Index()
        {
            if (Session["IdUsuario"] == null)
            {
                Response.Redirect(@"~\" + this.Cliente + @"\acesso"); return View();
            }

            AvaliacaoRepository oRepository = new AvaliacaoRepository();

            var lstAval = oRepository.GetAvaliacoesGestor(Convert.ToInt32(Session["IdCliente"]), Convert.ToInt32(Session["IdUsuario"]));

            AvaliacaoOnline.Data.Avaliacao avaliacao;
            if (lstAval.Count == 0)
                avaliacao = oRepository.GetAvaliacoes((int)Session["IdCliente"]).First();
            else
                avaliacao = lstAval.First();

            ViewData["CustomCSS"] = Url.Content("~" + UploadService.GetFileURL(@"/", avaliacao.ArquivoEstilo, avaliacao.IdCliente, avaliacao.Id));
            ViewData["CustomCSS"] = ViewData["CustomCSS"].ToString().EndsWith("/") ? "" : ViewData["CustomCSS"];
            ViewData["CustomBackground"] = Url.Content("~" + UploadService.GetFileURL(@"/", avaliacao.ImagemFundo, avaliacao.IdCliente, avaliacao.Id));
            ViewData["CustomBackground"] = ViewData["CustomBackground"].ToString().EndsWith("/") ? "" : ViewData["CustomBackground"];

            ViewData["NomeGestor"] = new UsuarioRepository().GetUsuario(Convert.ToInt32(Session["IdUsuario"])).Nome;


            return View(lstAval);
        }

        public ActionResult Resultado(int id)
        {
            return View();
        }


    }
}
